package com.sxm.yiwei.utils;

import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.DatePicker;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.TimePicker;


import com.sxm.yiwei.R;

import java.util.Calendar;

/**
 * Created by Administrator on 2017/9/7.
 */

public class WidgetUtil {
    public static void showPop(final Context mContext, final TextView textView){
        PopupWindow popupWindow = new PopupWindow(mContext);
        popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        View view = LayoutInflater.from(mContext).inflate(R.layout.select_container_pop, null);
        TextView tv_shoe_box = (TextView) view.findViewById(R.id.tv_shoe_box);
        TextView tv_computer_box = (TextView) view.findViewById(R.id.tv_computer_box);
        TextView tv_package = (TextView) view.findViewById(R.id.tv_package);
        tv_shoe_box.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                textView.setText("鞋盒");
            }
        });
        tv_computer_box.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                textView.setText("电脑主机箱");
            }
        });
        tv_package.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                textView.setText("大号行李箱");
            }
        });
        popupWindow.setContentView(view);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
        popupWindow.setOutsideTouchable(false);
        popupWindow.setFocusable(true);
        popupWindow.showAsDropDown(textView);



    }
   public  static void showDatePicker(Context context, final TextView textView) {
       Calendar c = Calendar.getInstance();
       new DatePickerDialog(context, 0, new DatePickerDialog.OnDateSetListener() {
           @Override
           public void onDateSet(DatePicker startDatePicker, int startYear, int startMonthOfYear,
                                 int startDayOfMonth) {
               String month=(startMonthOfYear+1)+"";
               if (month.length()<2){
                   month="0"+month;
               }
               String day=startDayOfMonth+"";
               if (day.length()<2){
                   day="0"+day;
               }
               StringBuilder date = new StringBuilder();
               //date.append(String.format("%d", startYear)).append("-").append((Integer.parseInt(String.format("%d", month))+1)).append("-").append(String.format("%d", day));
               date.append(String.format("%d", startYear)).append("-").append(month).append("-").append(day);

               textView.setText(date.toString());
               System.out.println("textString=========="+date.toString());

           }
       }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE)).show();
   }
    public static void showTimePicker(Context context, final TextView textView){
        Calendar c = Calendar.getInstance();
        new TimePickerDialog(context, 0, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                String hour=hourOfDay+"";
                if (hour.length()<2){
                    hour="0"+hour;
                }
                String minuteStr=(minute+1)+"";
                if (minuteStr.length()<2){
                    minuteStr="0"+minuteStr;
                }
                StringBuilder data = new StringBuilder();
                data.append(hour).append(":").append(minuteStr);
                textView.setText(data.toString());
            }
        },c.get(Calendar.HOUR),c.get(Calendar.MINUTE),true).show();

    }

    /*public static void showToast(Context context, String msg) {
        Toast toast = new Toast(context);
        //设置Toast显示位置，居中，向 X、Y轴偏移量均为0
        toast.setGravity(Gravity.CENTER, 0, 0);
        //获取自定义视图
        View view = LayoutInflater.from(context).inflate(R.layout.toast_view, null);
        TextView tvMessage = (TextView) view.findViewById(R.id.tv_message_toast);
        //设置文本
        tvMessage.setText(msg);
        //设置视图
        toast.setView(view);
        //设置显示时长
        toast.setDuration(Toast.LENGTH_LONG);
        //显示
        toast.show();
    }*/


}
